package com.hy.main.demo.rabbitmq;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;


/**
 * @Author yang DongYong
 * @Date 2022/5/8 - 05 - 08 - 22:36
 * @Description: com.hy.main.demo.rabbitmq
 * @version: 1.0
 */
public class RabbitMqUtils {

    public static Channel getChannel() {
        Channel channel = null;
        try {
            // 创建一个连接工厂
            ConnectionFactory factory = new ConnectionFactory();
            // 工厂ip 连接rabbitMq的队列
            factory.setHost("127.0.0.1");
            factory.setUsername("guest");
            factory.setPassword("guest");
            // 创建连接
            Connection connection = factory.newConnection();
            // 获取信道
             channel = connection.createChannel();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 返回一个信道
        return channel;
    }
}
